package com.olc.railing.base;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import com.olc.railing.dialog.ConfrimDialog;

import butterknife.ButterKnife;

public abstract class BaseFragment extends Fragment {


    private ProgressDialog pd;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(getLayoutResId(), null);
        ButterKnife.bind(this, view);
        init();
        return view;
    }

    /**
     * 获取布局文件
     * @return
     */
    public abstract int getLayoutResId();
    protected abstract void init();



    public void showProgressDialog(String msg) {
        pd = new ProgressDialog(getActivity());
        pd.setMessage(TextUtils.isEmpty(msg) ? "正在加载..." : msg);
        pd.setCancelable(true);
        pd.setCanceledOnTouchOutside(false);// 设置在点击Dialog外是否取消Dialog进度条
        pd.show();
    }

    public void hideProgressDialog() {
        if (pd != null && pd.isShowing())
            pd.dismiss();
    }



    protected void showConfrimDialog(String content) {
        new ConfrimDialog(getActivity(), "提示", content, new ConfrimDialog.OnMySubmitListener<String>() {
            @Override
            public void onSubmit(String var) {
            }

            @Override
            public void onClose() {

            }
        }).show();
    }
}